home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / lib.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  244 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* Lib.c */
  21.  
  22. #include <externs.h>
  23.  
  24. void AVL_SHOW_UNIT2(AVL_UNITDT_PTR w)
  25. {
  26.     int i, first, last, k;    
  27.     short co;
  28.     char msg[100];
  29.  
  30.     k = avl_cur_unit / 12;
  31.     first = k * 12;
  32.     last = first + 11;
  33.     if (last >= avl_size) 
  34.         last = avl_size - 1;
  35.  
  36.     
  37.     _settextposition(1,1);
  38.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n");
  39.     k = 1;
  40.     for(i = first; i <= last; ++i)  {
  41.         _settextposition(k,1);
  42.         if (i == avl_cur_unit)
  43.             co = _settextcolor(avl_men_ready);
  44.         else
  45.             co = _settextcolor(avl_men_letter);
  46.         sprintf(msg," %s %-6s %c%c/%c%c/%c%c %c%c:%c%c %-38s"
  47.             , (w -> s[i].status  == 'O') ? "Obsolete" : "Active  "
  48.             , (w -> s[i].is_main == 'M') ? "(Main)" : ""
  49.             , w -> s[i].cdate[0] / 10 + '0'
  50.             , w -> s[i].cdate[0] % 10 + '0'
  51.             , w -> s[i].cdate[1] / 10 + '0'
  52.             , w -> s[i].cdate[1] % 10 + '0'
  53.             , w -> s[i].cdate[2] / 10 + '0'
  54.             , w -> s[i].cdate[2] % 10 + '0'
  55.             , w -> s[i].cdate[3] / 10 + '0'
  56.             , w -> s[i].cdate[3] % 10 + '0'
  57.             , w -> s[i].cdate[4] / 10 + '0'
  58.             , w -> s[i].cdate[4] % 10 + '0'
  59.             , w -> s[i].fu
  60.             );
  61.         _outtext(msg);
  62.         ++k;
  63.         }
  64.     _settextcolor(co);
  65. }
  66.                 
  67. void AVL_UNIT2(AVL_UNITDT_PTR w)
  68. {
  69.     int x;
  70.     int r;
  71.     int no = 0;
  72.     int ch, cols = 80, rows;
  73.     AVL_WIN_PTR hw, hw2;
  74.     r = w -> ns;
  75.     if (r < 12)
  76.            rows = r;
  77.     else 
  78.         rows = 12;
  79.     avl_size = r;
  80.     avl_cur_unit = 0;
  81.  
  82.     hw2 = AVL_MAKE_WINDOW("",18,55,18+5,55+24,avl_wnd_bk_color,avl_wnd_color);
  83.     _outtext(" Use the arrow keys to\n");
  84.     _outtext(" go  over  the  units.\n");
  85.     _outtext("\n");
  86.     _outtext(" Press ESC to  cancel.");
  87.  
  88.     hw = AVL_MAKE_WINDOW(" Library's Contents ",4,1,rows+6,80,avl_wnd_bk_color,avl_wnd_color);
  89.  
  90.     while ( 1 )  {
  91.         AVL_SHOW_UNIT2(w);
  92.         ch = getch();
  93.         if (ch == 0 || ch == 0xE0) {
  94.             ch = getch();
  95.             switch( ch ) {
  96.                    case 73 : /* Page Up */ 
  97.                        avl_cur_unit -= rows;
  98.                        if (avl_cur_unit < 0)  
  99.                         avl_cur_unit = avl_size - 1;
  100.                        break;
  101.                    case 81 : /* Page Down */ 
  102.                        avl_cur_unit += rows;
  103.                        if (avl_cur_unit >= avl_size)
  104.                            avl_cur_unit = 0;
  105.                        break;
  106.                    case 72 : /* Up */ 
  107.                        if (--avl_cur_unit < 0)  
  108.                     avl_cur_unit = avl_size - 1;
  109.                        break;
  110.                    case 80 : /* Down */ 
  111.                        if (++avl_cur_unit >= avl_size)
  112.                            avl_cur_unit = 0;
  113.                        break;
  114.                    default : putchar(7); break;
  115.                    }
  116.             continue;
  117.             }
  118.         if (ch == 27)  {
  119.             AVL_DEL_WINDOW(hw);
  120.             AVL_DEL_WINDOW(hw2);
  121.             return;
  122.             }
  123.         putch(7);
  124.         continue;
  125.         }
  126. }            
  127.  
  128.                                 
  129. void  AVL_LIB_SELECT(AVL_UNITDT_PTR w)
  130. {
  131.     short rows, cols;
  132.     int i;
  133.     char msg[50];
  134.  
  135.     for(i = 0; i < w -> ns; ++i)  
  136.         if (!strcmp(w -> s[i].fu,"subprogram DUMMY")) {
  137.             AVL_DELETE_ONE(i,w);
  138.             --i;
  139.             continue;
  140.             }
  141. }
  142.  
  143. void AVL_MAKE_UNIT_DATE(AVL_UNITDT_PTR w)
  144. {
  145.     FILE *fp, *fopen();
  146.     char status[20];
  147.     char type[20];
  148.     char date[20];
  149.     char timex[20];
  150.     char unit[60];
  151.     char line[128];
  152.     int i, j, k;
  153.     w -> ns = 0;
  154.     fp = fopen("avllib.$$$","r");
  155.     k = 0;
  156.     if (fp == NULL)  
  157.         return;
  158.     if (fgets(line,127,fp) == NULL)  return;
  159.     do {
  160.         if (fgets(line,127,fp) == NULL)  {
  161.             if (feof(fp)) break;
  162.             AVL_ERROR("Error reading library. You should make a new library.");
  163.             fclose(fp);
  164.             return;
  165.             }
  166.         if (line[0] == 13) continue;
  167.         if (line[0] == 10) continue;
  168.         if (line[0] == '\n') continue;
  169.         if (strlen(line) < 1) continue;
  170.         for(i = j = 0; line[i] != ' '; ++i, ++j)
  171.             status[j] = line[i];
  172.         status[j] = '\0';
  173.         i = 11;
  174.         if (line[i] != ' ')  {
  175.             for(j = 0; line[i] != ' '; ++i, ++j)
  176.                 type[j] = line[i];
  177.             type[j] = '\0';
  178.             }
  179.         else strcpy(type,"  ");
  180.         i = 21;
  181.         for(j = 0; line[i] != ' '; ++i, ++j)
  182.             date[j] = line[i];
  183.         date[j] = '\0';
  184.         i = 30;
  185.         for(j = 0; line[i] != ' '; ++i, ++j)
  186.             timex[j] = line[i];
  187.         timex[j] = '\0';
  188.         i = 37;
  189.         for(j = 0; i < strlen(line); ++i, ++j)
  190.             unit[j] = line[i];
  191.         if (unit[j - 1] == '\n') --j;
  192.         unit[j] = '\0';
  193.         w -> s[k].status = status[0];
  194.         w -> s[k].is_main = type[1];
  195.         w -> s[k].cdate[0] = (date[0] - '0') * 10 + date[1] - '0';
  196.         w -> s[k].cdate[1] = (date[3] - '0') * 10 + date[4] - '0';
  197.         w -> s[k].cdate[2] = (date[6] - '0') * 10 + date[7] - '0';
  198.         w -> s[k].cdate[3] = (timex[0] - '0') * 10 + timex[1] - '0';
  199.         w -> s[k].cdate[4] = (timex[3] - '0') * 10 + timex[4] - '0';
  200.         strcpy(w -> s[k].fu,unit);
  201.         ++k;
  202.         } while (!feof(fp));
  203.     w -> ns = k;
  204.     fclose(fp);
  205. }
  206.  
  207.         
  208. void AVL_LIST_LIB()
  209. {
  210. /*    AVL_EDIT_WINDOW_PTR w;  */
  211.     AVL_WIN_PTR temp;
  212.     AVL_UNITDT w;
  213.     char msg[100];
  214.     char *bunit;
  215.     char *opts[17];
  216.     int cmd_ret_code, i;
  217.     FILE *fp, *fopen();
  218.     avl_blank_line[0] = '\0';
  219. /*    w = &avl_windows[avl_window];  */
  220.     w.ns = 0;
  221.     opts[0] = "Adalib2";
  222.     opts[1] = "-l";
  223.     opts[2] = avl_dir_library;
  224.     opts[3] = NULL;
  225.     temp = AVL_MAKE_WINDOW(" List Library ",5,1,9,80,avl_wnd_bk_color,avl_wnd_color);
  226.     _outtext("  Searching library. Please, wait a moment...\n");
  227.     if (AVL_EX_UNIT("ADALIB2", opts))  {
  228.         AVL_DEL_WINDOW(temp);
  229.         msg[0] = '\0';
  230.         AVL_MAKE_UNIT_DATE(&w);
  231.         if (w.ns > 0)  {
  232.             AVL_LIB_SELECT(&w);
  233.             if (w.ns != 0)  
  234.                 AVL_UNIT2(&w);
  235.             else
  236.                 AVL_ERROR("Library empty");
  237.             }            
  238.         else 
  239.             AVL_ERROR("Library empty");
  240.         }
  241.     avl_open_error_file = 0;
  242. }
  243.  
  244.